package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppUserLaHei;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterUserLaHeiDao.java
 * @Description 用户拉黑用户
 * @createTime 2021年07月29日 09:14:00
 */
@Repository
public class AfterUserLaHeiDao extends BaseDao<AppUserLaHei> {

    /**
     * 新增/更新
     * @param appUserLaHei
     */
    public void saveOrUpdate(AppUserLaHei appUserLaHei) {
        if (appUserLaHei!=null && appUserLaHei.getId() != null && appUserLaHei.getId()> 0) {
            this.update(appUserLaHei);
        } else {
            appUserLaHei.setId(this.add(appUserLaHei));
        }
    }

    /**
     * 综合查询
     * @param paramap
     * @param splitPageBean
     * @return
     */
    public List<AppUserLaHei> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_user_lahei where 1=1 ");
        if (StringEx.isNotNull(paramap.get("userid"))) {
            str.append(" and userid = ? ");
            list.add(paramap.get("userid"));
        }

        if (StringEx.isNotNull(paramap.get("nick"))) {
            str.append(" and nick = ? ");
            list.add(paramap.get("nick"));
        }

        if (StringEx.isNotNull(paramap.get("lhnick"))) {
            str.append(" and lhnick = ? ");
            list.add(paramap.get("lhnick"));
        }
        str.append(" order by createtime desc ");
        String sql = str.toString();
        return this.queryList(sql, list, AppUserLaHei.class, splitPageBean);
    }

    /**
     * 根据用户id和被拉黑用户ID查询拉黑信息
     * @param userid
     * @param lhuserid
     * @return
     */
    public AppUserLaHei getByUseridAndLhUserid(Integer userid, Integer lhuserid) {
        if(userid==null || userid<=0 || lhuserid==null || lhuserid<=0){
            return null;
        }
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_user_lahei where userid = ? and lhuserid = ? ");
        list.add(userid);
        list.add(lhuserid);
        String sql = str.toString();
        return this.queryObj(sql, list, AppUserLaHei.class);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id) {
        if(id== null || id<=0){
            return ;
        }
        ArrayList<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("delete from app_user_lahei where id = ? ");
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }


}